﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace CJAtech.BBS.Process
{
    public partial class BBSBaseController
    {
        /// <summary>
        /// 获取版块文章列表
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="isLoadRelatedRecord"></param>
        /// <returns></returns>
        [OutputCache(Duration = 2)]
        public virtual JsonResult GetArticleList(int? categoryId, int? pageIndex = 1, int? pageSize = 10, int? isLoadRelatedRecord = 1)
        {
            return Json(CurrentBBSProcess.GetArticleList(categoryId, pageIndex, pageSize, isLoadRelatedRecord), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 搜索文章列表
        /// </summary>
        /// <param name="keyword">搜索关键字</param>
        /// <param name="categoryId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="isLoadRelatedRecord"></param>
        /// <returns></returns>
        [OutputCache(Duration = 2)]
        public virtual JsonResult GetSearchArticleList(string keyword, int? categoryId, int? pageIndex = 1, int? pageSize = 10, int? isLoadRelatedRecord = 1)
        {
            return Json(CurrentBBSProcess.GetSearchArticleList(keyword, categoryId, pageIndex, pageSize, isLoadRelatedRecord), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取用户相关的文章列表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="isRelease"></param>
        /// <param name="pageIndex"></param>
        /// <param name="isLoadRelatedRecord"></param>
        /// <returns></returns>
        [OutputCache(Duration = 2)]
        public virtual JsonResult GetUserArticleList(string userId, int isRelease = 1, int? pageIndex = 1, int? isLoadRelatedRecord = 1)
        {
            return Json(CurrentBBSProcess.GetUserArticleList(userId, isRelease, pageIndex, isLoadRelatedRecord), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 获取文章详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="isLoadRelatedRecord"></param>
        /// <param name="isContentThumbnail"></param>
        /// <returns></returns>
        [OutputCache(Duration = 2)]
        public virtual JsonResult GetArticle(int? id, int? isLoadRelatedRecord = 1, int? isContentThumbnail = 0)
        {
            return Json(CurrentBBSProcess.GetArticle(id, isLoadRelatedRecord, isContentThumbnail), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 将图片生成缩略图
        /// </summary>
        /// <param name="pictureUrl"></param>
        /// <returns></returns>
        [OutputCache(Duration = 2)]
        public virtual ContentResult CreateThumbnailFromPicture(string pictureUrl)
        {
            return Content(CurrentBBSProcess.CreateThumbnailFromPicture(pictureUrl));
        }
        /// <summary>
        /// 文章点击数+1
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual JsonResult IncreaseViewCount(int? id)
        {
            return Json(CurrentBBSProcess.IncreaseViewCount(id, 1));
        }
        /// <summary>
        /// 文章点赞
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual JsonResult DiggArticle(int? id)
        {
            return Json(CurrentBBSProcess.DiggArticle(id), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 取消文章点赞
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual JsonResult UnDiggArticle(int? id)
        {
            return Json(CurrentBBSProcess.UnDiggArticle(id), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 文章点踩
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual JsonResult BuryArticle(int? id)
        {
            return Json(CurrentBBSProcess.BuryArticle(id), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 取消文章点踩
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public virtual JsonResult UnBuryArticle(int? id)
        {
            return Json(CurrentBBSProcess.UnBuryArticle(id), JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 用户发表文章
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateInput(false)]
        public virtual JsonResult AddArticle(int? categoryId, string title, string content, string imageList)
        {
            return Json(CurrentBBSProcess.AddArticle(categoryId, title, content, imageList));
        }
    }
}
